package com.leejxx.wemedia.controller.v1;

import com.leejxx.common.constants.wemedia.WemediaConstants;
import com.leejxx.model.common.dto.ResponseResult;
import com.leejxx.model.wemedia.dtos.WmMaterialDto;
import com.leejxx.wemedia.dao.WmMaterialDao;
import com.leejxx.wemedia.service.WmMaterialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author LeeJx
 * @ClassName WmMaterialController
 * @Description TODO
 * @date 2021/2/24 12:11
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile file) {
        log.info("[data]{}", file);
        return wmMaterialService.uploadPicture(file);
    }

    @RequestMapping("/list")
    public ResponseResult findList(@RequestBody WmMaterialDto wmMaterialDto) {
        log.info("[data]{}", wmMaterialDto);
        return wmMaterialService.findList(wmMaterialDto);
    }

    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable("id") Integer id) {
        log.info("[data]{}", id);
        return wmMaterialService.delPicture(id);
    }

    @GetMapping("/collect/{id}")
    public ResponseResult collectionMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.updateStatus(id, WemediaConstants.COLLECT_MATERIAL);
    }

    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollectionMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.updateStatus(id, WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }
}
